package com.yanqu.road.server.cmd.activity.cross;

import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.pb.activity.ActivityProto;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.pb.ActivityPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_CROSS_GENERAL_ACTIVITY_GET_UNION_RANK_REWARD_NOTIFY, desc = "跨服活动商会排行领奖 跨服返回")
public class CrossGeneralActivityGetUnionRankRewardNotifyCmd extends AbstractCommand {

    private int activityId;
    private int conditionType;
    private int conditionId;
    private int myRank;

    private ActivityRewardResult rewardResult;
    private int position;
    private String unionId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossActivityProto.CrossGeneralActivityGetRewardRespMsg reqMsg = CrossActivityProto.CrossGeneralActivityGetRewardRespMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionType = reqMsg.getConditionType();
        conditionId = reqMsg.getConditionId();
        myRank = reqMsg.getRank();
        position = reqMsg.getPosition();
        unionId = reqMsg.getUnionUid();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        rewardResult = player.getModule(ActivityModule.class).getCrossGeneralUnionRankActivityReward(activityId, conditionId,  myRank, position,unionId);
    }

    @Override
    public void sendData(GamePlayer player) {
        ActivityProto.ActivityGetRewardRespMsg.Builder respMsg = ActivityPb.parseActivityGetRewardRespMsg(rewardResult);
        if (null != respMsg) {
            player.sendPacket(Protocol.U_CROSS_GENERAL_ACTIVITY_GET_UNION_RANK_REWARD, respMsg);
        }
    }
}
